// ----------------------------------------
// Filename: configuration.h
// Description: The header file that contains the configurations for
//				micro RTOS
// Author: Jon Maloney
// Date: 8-Jun-2012
//

#ifndef CONFIGURATION_H
#define CONFIGURATION_H

//************************************************************
//                    Include .h files
//************************************************************
#include "types.h"
//************************************************************
//                    Include external references
//************************************************************
extern kernelBASE_TYPE uxCriticalNesting;
//************************************************************
//                    Define Statements
//************************************************************

#define _DEBUG 0
#define configIDLE_TASK_PRIORITY 0

//Defines the number of priority levels 
//	the operating system has.
#define configNB_PRIORITY_LEVELS 		16

#define configTICK_RATE_HZ				( ( kernelTickType ) 1000 )
#define configCPU_CLOCK_HZ  			( ( UINT32 ) 16000000 )  /* Fosc / 2 */
#define configKERNEL_INTERRUPT_PRIORITY	configNB_PRIORITY_LEVELS - 1
#define configTICK_TIMER_PRESCALE		1

#define configMAX_DELAY					65535

//************************************************************
//                    Struct, Union, enum Statements
//************************************************************

//************************************************************
//                    Global variables and constants
//************************************************************

//************************************************************
//                    Prototype Global Functions
//************************************************************





#define UnlockRegisters()		asm volatile ( 	"MOV 	#OSCCON,	w1		\n"		\
												"MOV 	#0x46, 		w2		\n"		\
												"MOV	#0x57, 		w3		\n"		\
												"MOV.b	w2, 		[w1]	\n"		\
												"MOV.b	w3, 		[w1]	\n"		\
												"BCLR 	OSCCON, 	#6"			);

#define LockRegisters()			asm volatile (	"MOV 	#OSCCON, 	w1 		\n"		\
												"MOV	#0x46, 		w2		\n"		\
												"MOV	#0x57,		w3		\n"		\
												"MOV.b	w2,			[w1]	\n"		\
												"MOV.b	w3,			[w1]	\n"		\
												"BSET	OSCCON,		#6"			)

#define DISABLE_INTERRUPTS()	_IPL = 0x07
#define ENABLE_INTERRUPTS()		_IPL = 0x00

#define ENTER_CRITICAL(){								\
							DISABLE_INTERRUPTS();		\
							uxCriticalNesting++;		\
						}

#define EXIT_CRITICAL() {									\
							uxCriticalNesting--;			\
							if( uxCriticalNesting == 0 )	\
							{								\
								ENABLE_INTERRUPTS();		\
							}								\
						}

#endif
